#include "stdafx.h"
#include "MyConfig.h"



//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMyConfig::CMyConfig()
{
	m_uFlag.dwCODE = 0;
	m_uFlag.bIoWritePermit = true;
	m_uFlag.bLoadSysTags = false;
	m_uFlag.bLoadIoFields = true;
	m_uFlag.bLoadOnlyIoStatus = true;
	m_csBrokerURL = "opc.mqtt://127.0.0.1:1883";
	m_csTopic = "symlink/opcua";
	m_csClientID = "SymLink_OPCUA_Publisher";
	m_csPublishID = "SymLink_OPCUA_Publisher";
}

CMyConfig::~CMyConfig()
{

}


void CMyConfig::OnLoad(CMarkup& oMarkup)
{
	std::string csData;

	oMarkup.ResetMainPos();
	oMarkup.FindElem();

	//m_uLogCtrl.bIsInfo = atoi(oMarkup.GetAttrib("info"));
	//m_uLogCtrl.bIsDebug = atoi(oMarkup.GetAttrib("debug"));

	oMarkup.IntoElem();
	if(oMarkup.FindElem("params"))
	{
		m_uFlag.dwCODE = atoi(oMarkup.GetAttrib("uflg").c_str());
		m_csRoot = oMarkup.GetAttrib("root");
		if (m_csRoot.empty()) {
			m_csRoot = "symlink_datas";
		}
		m_csBrokerURL = oMarkup.GetAttrib("broker");
		if (m_csBrokerURL.empty()) {
			m_csBrokerURL = "opc.mqtt://127.0.0.1:1883";
		}
		m_csTopic = oMarkup.GetAttrib("topic");
		if (m_csTopic.empty()) {
			m_csTopic = "symlink/opcua";
		}
		m_csClientID = oMarkup.GetAttrib("cid");
		if (m_csClientID.empty()) {
			m_csClientID = "SymLink_OPCUA_Publisher";
		}
		m_csPublishID = oMarkup.GetAttrib("pid");
		if (m_csPublishID.empty()) {
			m_csPublishID = "SymLink_OPCUA_Publisher";
		}
		m_csUser = oMarkup.GetAttrib("user");
		m_csPasswd = oMarkup.GetAttrib("passwd");
	}

	if(oMarkup.FindElem("adv"))
	{
		//m_tAdv.nModelSplit = atoi(oMarkup.GetAttrib("uflg").c_str());

	}
	oMarkup.OutOfElem();

}

void CMyConfig::OnSave(CMarkup& oMarkup)
{
	oMarkup.SetDoc("<?xml version=\"1.0\" encoding=\"GBK\"?>\r\n");
	oMarkup.AddElem("root");
	//oMarkup.AddAttrib("info", m_uLogCtrl.bIsInfo);
	//oMarkup.AddAttrib("debug", m_uLogCtrl.bIsDebug);

	oMarkup.IntoElem();
	oMarkup.AddElem("params");
	{
		oMarkup.AddAttrib("uflg",m_uFlag.dwCODE);
		oMarkup.AddAttrib("root",m_csRoot);
		oMarkup.AddAttrib("broker",m_csBrokerURL);
		oMarkup.AddAttrib("cid",m_csClientID);
		oMarkup.AddAttrib("pid",m_csPublishID);
		oMarkup.AddAttrib("user",m_csUser);
		oMarkup.AddAttrib("passwd",m_csPasswd);
	}
	oMarkup.AddElem("adv");
	{
		//oMarkup.AddAttrib("uflg",m_tAdv.nModelSplit);
	}
	oMarkup.OutOfElem();
}

